/* Vue的基础使用 */
let vm = new Vue({
    // 构建数据
    data: {
        list: [{
            id: 1,
            count: 2,
            price: 12.5
        }, {
            id: 2,
            count: 0,
            price: 10.5
        }, {
            id: 3,
            count: 3,
            price: 8.5
        }, {
            id: 4,
            count: 0,
            price: 8
        }, {
            id: 5,
            count: 0,
            price: 14.5
        }]
    },
    // 计算属性
    computed: {
        sub() {
            let counts = 0,
                prices = 0;
            this.list.forEach(item => {
                counts += item.count;
                prices += item.count * item.price;
            });
            return {
                counts,
                prices
            };
        }
    },
    // 普通方法
    methods: {
        change(index, type) {
            let item = this.list[index];
            if (type === 'minus') {
                item.count--;
                if (item.count < 0) item.coun = 0;
                return;
            }
            item.count++;
        }
    }
});
// 指定视图
vm.$mount('#computedBox');